package ru.eas.graph;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CyclicGraph {

    public static void main(String[] args) {
//        String testString = "4 4\n" +
//                "1 2\n" +
//                "4 1\n" +
//                "2 3\n" +
//                "3 1";
//        Scanner scanner = new Scanner(testString);

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        DirectedGraph graph = new DirectedGraph(n);
        for (int i = 0; i < m; i++) {
            graph.addEdge(scanner.nextInt(), scanner.nextInt());
        }
        System.out.print(graph.hasCycle() ? "True" : "False");
    }

    static class DirectedGraph {
        public static final int UNFINISHED = 0;

        private List<List<Integer>> vertices;
        private boolean[] visited;
        private int connectedComponentsCount;
        private int timer;
        private int[] visitStart;
        private int[] visitEnd;
        private boolean hasCycle;


        public DirectedGraph(int vertexCount) {
            vertexCount++;
            vertices = new ArrayList<List<Integer>>(vertexCount);
            for (int i = 0; i < vertexCount; i++) {
                vertices.add(new ArrayList<Integer>());
            }
            visited = new boolean[vertexCount];
            visitStart = new int[vertexCount];
            visitEnd = new int[vertexCount];
        }

        public void addEdge(int vertex1, int vertex2) {
            vertices.get(vertex1).add(vertex2);
        }

        private void clearVisited() {
            for (int i = 0; i < visited.length; i++) {
                visited[i] = false;
            }
        }

        public int getConnectedComponentCount() {
            dfs();
            return connectedComponentsCount;
        }

        public boolean hasCycle() {
            timer = 0;
            hasCycle = false;
            dfs();
            return hasCycle;
        }

        private void dfs() {
            clearVisited();
            connectedComponentsCount = 0;
            for (int i = 1; i < vertices.size(); i++) {
                if (visited[i] == false) {
                    connectedComponentsCount++;
                    explore(i);
                }
            }
        }

        public void explore(int vertex) {
            visited[vertex] = true;
            visitStart[vertex] = ++timer;
            for (int v : vertices.get(vertex)) {
                if (visited[v] == false) {
                    explore(v);
                }
                if (visitEnd[v] == UNFINISHED) {
                    hasCycle = true;
                }
            }
            visitEnd[vertex] = ++timer;
        }
    }
}
